﻿using System;
using System.Collections;

namespace SharpSqlAnalyzer
{
	// Token: 0x0200006A RID: 106
	public class TSourceTokenList : IEnumerable
	{
		// Token: 0x06000245 RID: 581 RVA: 0x002DA284 File Offset: 0x002D8484
		IEnumerator IEnumerable.GetEnumerator()
		{
			return this.items.GetEnumerator();
		}

		// Token: 0x17000037 RID: 55
		public TSourceToken this[int pos]
		{
			get
			{
				if (pos < 0 || pos >= this.size())
				{
					throw new IndexOutOfRangeException();
				}
				return (TSourceToken)this.items[pos];
			}
		}

		// Token: 0x17000038 RID: 56
		// (get) Token: 0x06000247 RID: 583 RVA: 0x002DA2B7 File Offset: 0x002D84B7
		public int Count
		{
			get
			{
				return this.size();
			}
		}

		// Token: 0x06000248 RID: 584 RVA: 0x002DA2BF File Offset: 0x002D84BF
		public virtual void resetiterator()
		{
			this.iteratorpos = -1;
		}

		// Token: 0x06000249 RID: 585 RVA: 0x002DA2C8 File Offset: 0x002D84C8
		public virtual bool hasNext()
		{
			bool flag = this.iteratorpos < this.items.Count - 1;
			if (flag)
			{
				this.iteratorpos++;
			}
			return flag;
		}

		// Token: 0x0600024A RID: 586 RVA: 0x002DA2F0 File Offset: 0x002D84F0
		public virtual TSourceToken next()
		{
			return (TSourceToken)this.items[this.iteratorpos];
		}

		// Token: 0x0600024B RID: 587 RVA: 0x002DA308 File Offset: 0x002D8508
		public virtual void remove()
		{
			throw new NotSupportedException();
		}

		// Token: 0x0600024C RID: 588 RVA: 0x002DA30F File Offset: 0x002D850F
		public TSourceTokenList()
		{
			this.items = new ArrayList();
			this.curpos = -1;
			this.resetiterator();
		}

		// Token: 0x0600024D RID: 589 RVA: 0x002DA336 File Offset: 0x002D8536
		public virtual TSourceToken get(int index)
		{
			return (TSourceToken)this.items[index];
		}

		// Token: 0x0600024E RID: 590 RVA: 0x002DA349 File Offset: 0x002D8549
		public virtual void add(TSourceToken st)
		{
			this.items.Add(st);
		}

		// Token: 0x0600024F RID: 591 RVA: 0x002DA358 File Offset: 0x002D8558
		public virtual void add(int index, TSourceToken st)
		{
			this.items.Insert(index, st);
		}

		// Token: 0x06000250 RID: 592 RVA: 0x002DA367 File Offset: 0x002D8567
		public virtual void remove(int index)
		{
			this.items.RemoveAt(index);
		}

		// Token: 0x06000251 RID: 593 RVA: 0x002DA375 File Offset: 0x002D8575
		public virtual void remove(TSourceToken st)
		{
			this.items.Remove(st);
		}

		// Token: 0x06000252 RID: 594 RVA: 0x002DA383 File Offset: 0x002D8583
		public virtual int size()
		{
			return this.items.Count;
		}

		// Token: 0x06000253 RID: 595 RVA: 0x002DA390 File Offset: 0x002D8590
		public virtual void clear()
		{
			this.items.Clear();
		}

		// Token: 0x06000254 RID: 596 RVA: 0x002DA3A0 File Offset: 0x002D85A0
		internal virtual bool isnonsolidtoken(TSourceToken st, bool pcmtissolidtoken)
		{
			bool result = false;
			ETokenType tokentype = st.tokentype;
			if (tokentype - ETokenType.ttreturn > 1)
			{
				if (tokentype - ETokenType.ttsimplecomment <= 1)
				{
					if (!pcmtissolidtoken)
					{
						result = true;
					}
				}
			}
			else
			{
				result = true;
			}
			return result;
		}

		// Token: 0x06000255 RID: 597 RVA: 0x002DA3CE File Offset: 0x002D85CE
		public virtual TSourceToken nextsolidtoken(TSourceToken ptoken, int pstep, bool pcmtissolidtoken)
		{
			if (ptoken == null)
			{
				return null;
			}
			if (ptoken.posinlist == -1)
			{
				return null;
			}
			return this.nextsolidtoken(ptoken.posinlist, pstep, pcmtissolidtoken);
		}

		// Token: 0x06000256 RID: 598 RVA: 0x002DA3F0 File Offset: 0x002D85F0
		public virtual TSourceToken nextsolidtoken(int ptokenpos, int pstep, bool pcmtissolidtoken)
		{
			TSourceToken result = null;
			if (this.items == null)
			{
				return result;
			}
			if (ptokenpos < 0)
			{
				return result;
			}
			if (ptokenpos > this.size() - 1)
			{
				return result;
			}
			if (pstep > 0 && ptokenpos == this.size() - 1)
			{
				return result;
			}
			int num = 0;
			if (pstep > 0)
			{
				for (int i = ptokenpos + 1; i < this.size(); i++)
				{
					TSourceToken st = this.get(i);
					if (!this.isnonsolidtoken(st, pcmtissolidtoken))
					{
						num++;
						if (num == pstep)
						{
							result = this.get(i);
							break;
						}
					}
				}
			}
			if (pstep < 0)
			{
				for (int j = ptokenpos - 1; j >= 0; j--)
				{
					TSourceToken st2 = this.get(j);
					if (!this.isnonsolidtoken(st2, pcmtissolidtoken))
					{
						num++;
						if (num == Math.Abs(pstep))
						{
							result = this.get(j);
							break;
						}
					}
				}
			}
			return result;
		}

		// Token: 0x06000257 RID: 599 RVA: 0x002DA4B0 File Offset: 0x002D86B0
		public virtual int nextObjectNameToken(int ptokenpos, int pstep, bool pcmtissolidtoken)
		{
			int num = -1;
			bool flag = false;
			if (this.items == null)
			{
				return num;
			}
			if (ptokenpos < 0)
			{
				return num;
			}
			if (ptokenpos > this.size() - 1)
			{
				return num;
			}
			if (pstep > 0 && ptokenpos == this.size() - 1)
			{
				return num;
			}
			int num2 = 0;
			if (pstep > 0)
			{
				for (int i = ptokenpos + 1; i < this.size(); i++)
				{
					TSourceToken tsourceToken = this.get(i);
					if (!this.isnonsolidtoken(tsourceToken, pcmtissolidtoken))
					{
						if (tsourceToken.tokencode == 46)
						{
							flag = true;
						}
						else if (num == -1)
						{
							num = i;
						}
						else if (flag)
						{
							flag = false;
							num = i;
						}
						else
						{
							num2++;
							if (num2 == pstep)
							{
								break;
							}
						}
					}
				}
			}
			if (pstep < 0)
			{
				for (int j = ptokenpos - 1; j >= 0; j--)
				{
					TSourceToken tsourceToken2 = this.get(j);
					if (!this.isnonsolidtoken(tsourceToken2, pcmtissolidtoken))
					{
						if (tsourceToken2.tokencode == 46)
						{
							flag = true;
						}
						else if (num == -1)
						{
							num = j;
						}
						else if (flag)
						{
							flag = false;
							num = j;
						}
						else
						{
							num2++;
							if (num2 == Math.Abs(pstep))
							{
								break;
							}
						}
					}
				}
			}
			return num;
		}

		// Token: 0x06000258 RID: 600 RVA: 0x002DA5A0 File Offset: 0x002D87A0
		internal virtual int solidtokenafterpos(int piindex, string psstr, int scope, string ignoretoken)
		{
			int num = 0;
			if (this.items == null)
			{
				return num;
			}
			if (piindex < 0)
			{
				return num;
			}
			if (piindex > this.size() - 2)
			{
				return num;
			}
			int num2 = 0;
			for (int i = piindex + 1; i < this.size(); i++)
			{
				if (!this.get(i).isnonsolidtoken() && (ignoretoken.Length <= 0 || TBaseType.mycomparetext(this.get(i).astext, ignoretoken) != 0))
				{
					if (TBaseType.mycomparetext(psstr, this.get(i).astext) == 0)
					{
						num = i;
					}
					num2++;
					if (num > 0 || num2 >= scope)
					{
						break;
					}
				}
			}
			return num;
		}

		// Token: 0x06000259 RID: 601 RVA: 0x002DA634 File Offset: 0x002D8834
		public virtual int solidtokenafterpos(int pStart, int pTokenCode, int pSteps, string pIgnoreThisString)
		{
			int num = 0;
			if (this.items == null)
			{
				return num;
			}
			if (pStart < 0)
			{
				return num;
			}
			if (pStart > this.size() - 2)
			{
				return num;
			}
			int num2 = 0;
			for (int i = pStart + 1; i < this.size(); i++)
			{
				if (!this.get(i).isnonsolidtoken() && (pIgnoreThisString.Length <= 0 || TBaseType.mycomparetext(this.get(i).astext, pIgnoreThisString) != 0))
				{
					if (pTokenCode == this.get(i).tokencode)
					{
						num = i;
					}
					num2++;
					if (num > 0 || num2 >= pSteps)
					{
						break;
					}
				}
			}
			return num;
		}

		// Token: 0x0600025A RID: 602 RVA: 0x002DA6C0 File Offset: 0x002D88C0
		public virtual TSourceToken solidtokenbefore(int pStart)
		{
			return this.nextsolidtoken(pStart, -1, false);
		}

		// Token: 0x0600025B RID: 603 RVA: 0x002DA6CB File Offset: 0x002D88CB
		public virtual bool sqlplusaftercurtoken()
		{
			return this.sqlplusaftertoken(this.curpos) > 0;
		}

		// Token: 0x0600025C RID: 604 RVA: 0x002DA6DC File Offset: 0x002D88DC
		internal virtual int sqlplusaftertoken(int pStart)
		{
			int result = 0;
			if (this.items == null)
			{
				return result;
			}
			if (pStart < 0 || pStart + 1 > this.size() - 1)
			{
				return result;
			}
			int i = pStart + 1;
			while (i < this.size())
			{
				if (!this.get(i).isnonsolidtoken())
				{
					if (this.get(i).tokencode == 273)
					{
						result = i;
						break;
					}
					break;
				}
				else
				{
					i++;
				}
			}
			return result;
		}

		// Token: 0x0600025D RID: 605 RVA: 0x002DA741 File Offset: 0x002D8941
		public virtual bool returnaftercurtoken(bool ignorecmt)
		{
			return this.returnaftertoken(this.curpos, ignorecmt) > 0;
		}

		// Token: 0x0600025E RID: 606 RVA: 0x002DA754 File Offset: 0x002D8954
		internal virtual int returnaftertoken(int pStart, bool ignorecomment)
		{
			int result = 0;
			int num = 0;
			if (this.items == null)
			{
				return result;
			}
			if (pStart < 0 || pStart + 1 > this.size() - 1)
			{
				return result;
			}
			for (int i = pStart + 1; i < this.size(); i++)
			{
				num = i;
				if (this.get(i).tokentype != ETokenType.ttwhitespace && ((this.get(i).tokentype != ETokenType.ttsimplecomment && this.get(i).tokentype != ETokenType.ttbracketedcomment) || !ignorecomment))
				{
					break;
				}
			}
			if (this.get(num).tokentype == ETokenType.ttreturn)
			{
				result = num - pStart;
			}
			return result;
		}

		// Token: 0x0600025F RID: 607 RVA: 0x002DA7E0 File Offset: 0x002D89E0
		public virtual bool returnbeforecurtoken(bool ignorecomment)
		{
			bool result = false;
			if (this.items == null)
			{
				return result;
			}
			if (this.curpos <= 0)
			{
				return result;
			}
			if (this.curpos > this.size() - 1)
			{
				return result;
			}
			int i = this.curpos - 1;
			while (i >= 0)
			{
				if (this.get(i).tokentype != ETokenType.ttwhitespace && (!ignorecomment || (this.get(i).tokentype != ETokenType.ttsimplecomment && this.get(i).tokentype != ETokenType.ttbracketedcomment)))
				{
					if (this.get(i).tokentype == ETokenType.ttreturn)
					{
						result = true;
						break;
					}
					break;
				}
				else
				{
					i--;
				}
			}
			return result;
		}

		// Token: 0x06000260 RID: 608 RVA: 0x002DA870 File Offset: 0x002D8A70
		public virtual TSourceToken searchToken(int targetTokenCode, string targetTokenText, TSourceToken startToken, int range)
		{
			TSourceToken result = null;
			if (this.items == null)
			{
				return result;
			}
			int posinlist = startToken.posinlist;
			if (posinlist < 0 || (posinlist > this.size() - 1 && range > 0))
			{
				return result;
			}
			if (range > 0 && posinlist == this.size() - 1)
			{
				return result;
			}
			if (range < 0 && posinlist == 0)
			{
				return result;
			}
			if (range == 0)
			{
				if (targetTokenCode > 0)
				{
					if (startToken.tokencode == targetTokenCode)
					{
						result = startToken;
					}
				}
				else if (startToken.ToString().Equals(targetTokenText, StringComparison.CurrentCultureIgnoreCase))
				{
					result = startToken;
				}
				return result;
			}
			if (range > 0)
			{
				for (int i = posinlist + 1; i < this.size(); i++)
				{
					TSourceToken tsourceToken = this.get(i);
					if (!this.isnonsolidtoken(tsourceToken, false))
					{
						if (--range < 0)
						{
							break;
						}
						if (targetTokenCode > 0)
						{
							if (tsourceToken.tokencode == targetTokenCode)
							{
								result = tsourceToken;
								break;
							}
						}
						else if (tsourceToken.ToString().Equals(targetTokenText, StringComparison.CurrentCultureIgnoreCase))
						{
							result = tsourceToken;
							break;
						}
					}
				}
				range = 0;
			}
			if (range < 0)
			{
				for (int j = posinlist - 1; j >= 0; j--)
				{
					TSourceToken tsourceToken = this.get(j);
					if (!this.isnonsolidtoken(tsourceToken, false))
					{
						if (++range > 0)
						{
							break;
						}
						if (targetTokenCode > 0)
						{
							if (tsourceToken.tokencode == targetTokenCode)
							{
								result = tsourceToken;
								break;
							}
						}
						else if (tsourceToken.ToString().Equals(targetTokenText, StringComparison.CurrentCultureIgnoreCase))
						{
							result = tsourceToken;
							break;
						}
					}
				}
			}
			return result;
		}

		// Token: 0x06000261 RID: 609 RVA: 0x002DA9A0 File Offset: 0x002D8BA0
		public virtual void setTokenStatus(ETokenStatus ps, int pstart, int pend)
		{
			if (pstart < 0)
			{
				return;
			}
			if (pend > this.size() - 1)
			{
				return;
			}
			for (int i = pstart; i <= pend; i++)
			{
				this.get(i).tokenstatus = ps;
			}
		}

		// Token: 0x06000262 RID: 610 RVA: 0x002DA9D7 File Offset: 0x002D8BD7
		public virtual int indexOf(TSourceToken pst)
		{
			return this.items.IndexOf(pst);
		}

		// Token: 0x04001060 RID: 4192
		internal int iteratorpos = -1;

		// Token: 0x04001061 RID: 4193
		internal ArrayList items;

		// Token: 0x04001062 RID: 4194
		internal int curpos;
	}
}
